|
|
Christopher James Huff wrote:
>In article <cja### [at] netplexaussieorg>,
> Christopher James Huff <cja### [at] earthlinknet> wrote:
>
>> The point will be in a plane perpendicular to a line between the two
>> known points and passing through the midpoint. You can easily calculate
>> this plane and find the intersection of the ray with it (with trace() or
>> by using the plane equation), but as I mentioned, with a line it can go
>> off to infinity, and with a ray there is sometimes no solution.
>
>#macro CompPoint(pA, pB, rayStart, rayDir)
>// The midpoint and plane normal.
> #local midPt = (pA + pB)/2;
> #local Norm = vnormalize(pB - pA);
>
>// Compensate for the plane not passing through the origin.
> #local lRayStart = rayStart - midPt;
>
>// Solve for intersection distance with line.
> #local T = (vdot(Norm, lRayStart)/vdot(Norm, rayDir))
>
>// If T is > 0, there is a ray intersection at rayStart + rayDir*T.
>// Otherwise, no intersection. You'll need to fill in the blank.
>#end
>
>Untested, I may have made an error, or trace() might be a better idea,
>it would certainly be simpler.
I think this line;
#local lRayStart = rayStart - midPt;
- should have been:
#local lRayStart = midPt - rayStart;
And there should be no need to normalize
the normal vector.
Here's how I would have written that macro:
#macro CompPoint(pA, pB, pRayStart, vRayDir)
#local pMid = (pA + pB)/2;
#local vNorm = pB - pA;
#local T =
vdot(pMid - pRayStart, vNorm)/vdot(vRayDir, vNorm);
(pRayStart + T*vRayDir)
#end // CompPoint
And here's how I would test the ray:
#declare pHit = CompPoint(p0, p1, pRay, vRay);
#if (vdot(pHit - pRay, vRay) < 0)
#debug "There is no point on the ray that has"
#debug "equal distances to both points."
#end
But I have not tested my code either,
so I too could be wrong.
Tor Olav
Post a reply to this message
|
|